package com.hmall.search.web;

import com.hmall.common.dto.PageDTO;
import com.hmall.search.doc.ItemDoc;
import com.hmall.search.pojo.RequestParams;
import com.hmall.search.service.SearchService;
import org.checkerframework.checker.units.qual.A;
import org.elasticsearch.action.search.SearchRequest;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.RestHighLevelClient;
import org.elasticsearch.search.suggest.Suggest;
import org.elasticsearch.search.suggest.SuggestBuilder;
import org.elasticsearch.search.suggest.SuggestBuilders;
import org.elasticsearch.search.suggest.completion.CompletionSuggestion;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/search")
public class SearchController {

    @Autowired
    private SearchService searchService;

    //搜索栏自动补全
    @GetMapping("/suggestion")
    public List<String> itemSuggestion(@RequestParam String key) {
       return searchService.itemSuggestion(key);
    }

    //过滤项聚合
    @PostMapping("/filters")
    public Map<String,List<String>> itemFilters(@RequestBody RequestParams requestParams){
        return searchService.itemFilters(requestParams);
    }

    //基本搜索功能
    @PostMapping("/list")
    public PageDTO<ItemDoc> itemList(@RequestBody RequestParams requestParams){
        return searchService.itemList(requestParams);
    }

}
